#include <iostream>

using namespace std;
#define TreeElemType string
#define Status int
#define OK 1
#define Fail 0
typedef struct BiTreeNode {
    TreeElemType data;
    struct BiTreeNode *left = NULL, *right = NULL;
} BiTreeNode, *BiTree;

int TransNum(string s) {
    int f = 0;
    for (int i = 0; i < s.length(); ++i) {
        f = f * 10 + s[i] - '0';
    }
    return f;
}

int Compute(BiTree root) {
    if (!root->left && !root->right) return TransNum(root->data);
    int a, b;
    if (root->left)
        a = Compute(root->left);
    if (root->right)
        b = Compute(root->right);
    switch (root->data[0]) {
        case '+':
            return a + b;
        case '-':
            return a - b;
        case '*':
            return a * b;
    }
}

TreeElemType s[] = {"*", "+", "-", "3", "2", "+", "*", "", "", "", "", "4", "2", "2", "1"};

BiTree BuildTree(int step) {
    BiTree root = new BiTreeNode;
    if (step > 15 || !s[step - 1].length()) return NULL;
    root->data = s[step - 1];
    root->left = BuildTree(step * 2);
    root->right = BuildTree(step * 2 + 1);
    return root;
}

int main() {
    BiTree root = BuildTree(1);
    cout << Compute(root) << endl;
}
